<template>
    <div class="page-container">
        <div>
            <div class="operation-container">
                <el-button type="primary" @click="onPrint">打印</el-button>
            </div>
            <div id="deviceDispatchPrint" class="print-container">
                <div class="print-title">经营维护申请单</div>
                <table class="table-class" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="print-label">时间</td>
                        <td class="print-input-content2">
                            {{formatUtil.dateFormat(form.maintainTime)}}
                        </td>
                        <td class="print-label">部门</td>
                        <td class="print-input-content2">
                            {{form.deptName}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">地点</td>
                        <td class="print-input-content" colspan="3">
                            {{form.maintainAddress}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">参加人员</td>
                        <td class="print-input-content" colspan="3">
                            {{form.joinMans}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">拜访单位</td>
                        <td class="print-input-content2">
                            {{form.visitDepart}}
                        </td>
                        <td class="print-label">拜访人员及职位</td>
                        <td class="print-input-content2">
                            {{form.visitManPosition}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">预计费用（元）</td>
                        <td class="print-input-content2">
                            {{form.planPrice}}
                        </td>
                        <td class="print-label">是否含酒水</td>
                        <td class="print-input-content2">
                            {{form.isWine == 1 ? '是' : '否'}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">事由及预期效果</td>
                        <td class="print-input-content" colspan="3">
                            {{form.activityExpect}}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label-line" colspan="4">
                            审批信息
                        </td>
                    </tr>
                    <tr>
                        <td class="print-table-line" colspan="4">
                            <table border="0" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr>
                                        <th>审批人</th>
                                        <th>流程节点名称</th>
                                        <th>审批结果</th>
                                        <th>审批意见</th>
                                        <th>审批时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="item in flowList">
                                        <td>{{item.checkName}}</td>
                                        <td>{{item.nodeName}}</td>
                                        <td>{{item.dealType}}</td>
                                        <td>{{item.remark}}</td>
                                        <td>{{formatUtil.timeFormat(item.endTime)}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</template>
<script>
import { ref, toRefs, reactive, onMounted } from 'vue'
import { ElNotification } from 'element-plus'
import http from '@/http.js'
import printJS from 'print-js'
import formatUtil from '@/utils/format.js'

export default {
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    components: {

    },
    setup(props, ctx) {

        const state = reactive({
            form: {},
            flowList: []
        })

        const loadDetail = () => {
            http.fetchForm({
                url: '/activiti/flow/getDetails',
                data: {
                    taskId: props.id,
                    taskType: 'act_maintain'
                },
            }).then((res) => {
                let data = res.data.detail;
                console.log(data);
                state.form = data;
                state.flowList = res.data.flowHis;
            })
        }

        const onPrint = () => {
            printJS({
                printable: 'deviceDispatchPrint',
                type: 'html',
                targetStyles: ['*'],
                style: '@page{margin-top: 1mm;margin-bottom: 1mm;}'
            })
        }

        onMounted(() => {
            loadDetail();
        });

        return {
            formatUtil,
            ...toRefs(state),
            onPrint
        }
    }
}
</script>
<style scoped>
@import '@/assets/css/print.css';
</style>